﻿''' <summary>
''' 轨迹线的基类
''' </summary>
''' <remarks></remarks>
Public MustInherit Class TrochoidBase
    Implements ITrochoid


#Region "variables"
    ''' <summary>
    ''' 主窗体的区域
    ''' </summary>
    Protected m_MainRect As Rectangle = Nothing

#End Region

#Region "properties"

    Private m_FormCollection As List(Of ImageForm) = Nothing
    Public ReadOnly Property FormCollection() As List(Of ImageForm)
        Get
            Return m_FormCollection
        End Get
    End Property


    Private m_ItemSize As Size = Size.Empty
    ''' <summary>
    ''' 
    ''' </summary>
    Public Property ItemSize() As System.Drawing.Size Implements ITrochoid.ItemSize
        Get
            Return Me.m_ItemSize
        End Get
        Set(ByVal value As System.Drawing.Size)
            Me.m_ItemSize = value
        End Set
    End Property


#End Region

    Public Sub New()
        Me.m_FormCollection = New List(Of ImageForm)()
        Me.Init()
    End Sub

    Public Sub New(ByVal mainRect As Rectangle)
        Me.m_FormCollection = New List(Of ImageForm)()
        Me.m_MainRect = mainRect
        Console.WriteLine(mainRect)
        Me.Init()
    End Sub



    Private Sub DisposeItem(ByVal frm As ImageForm)
         frm.Invoke(New Action(AddressOf frm.Hide))
        'If frm.IsDisposed = False Then
        '    frm.Invoke(New Action(AddressOf frm.Close))
        'End If
    End Sub


    Public MustOverride Sub Init() Implements ITrochoid.Init

    Public Overridable Sub Show() Implements ITrochoid.Show
        For Each item As ImageForm In Me.m_FormCollection
            item.Show()
        Next
    End Sub

    Public Overridable Sub Hide() Implements ITrochoid.Hide
        For Each item As ImageForm In Me.m_FormCollection
            item.Hide()
        Next
    End Sub



    Public Overridable Sub Move(ByVal x As Integer, ByVal y As Integer) Implements ITrochoid.Move
        For Each item As ImageForm In Me
            item.UpdateLocation(item.Left + x, item.Top + y)
        Next
    End Sub

    Public Function Find(ByVal frm As ImageForm) As ImageForm Implements ITrochoid.Find
        For Each _ImageForm As ImageForm In Me.m_FormCollection
            If _ImageForm.ProgramInfo.Id.Equals(frm.ProgramInfo.Id) Then
                Return _ImageForm
            End If
        Next
        Return Nothing
    End Function

    Public Sub Add(ByVal item As ImageForm) Implements System.Collections.Generic.ICollection(Of ImageForm).Add
        Me.m_FormCollection.Add(item)
    End Sub

    Public Sub Clear() Implements System.Collections.Generic.ICollection(Of ImageForm).Clear
        For Each item As ImageForm In Me.m_FormCollection
            Me.DisposeItem(item)
        Next
        Me.m_FormCollection.Clear()
    End Sub

    Public Function Contains(ByVal item As ImageForm) As Boolean Implements System.Collections.Generic.ICollection(Of ImageForm).Contains
        Return Me.m_FormCollection.Contains(item)
    End Function

    Public Sub CopyTo(ByVal array() As ImageForm, ByVal arrayIndex As Integer) Implements System.Collections.Generic.ICollection(Of ImageForm).CopyTo
        Me.m_FormCollection.CopyTo(array, arrayIndex)
    End Sub

    Public ReadOnly Property Count() As Integer Implements System.Collections.Generic.ICollection(Of ImageForm).Count
        Get
            Return Me.m_FormCollection.Count
        End Get
    End Property

    Public ReadOnly Property IsReadOnly() As Boolean Implements System.Collections.Generic.ICollection(Of ImageForm).IsReadOnly
        Get
            Return False
        End Get
    End Property

    Public Function Remove(ByVal item As ImageForm) As Boolean Implements System.Collections.Generic.ICollection(Of ImageForm).Remove
        Return Me.m_FormCollection.Remove(item)
    End Function

    Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of ImageForm) Implements System.Collections.Generic.IEnumerable(Of ImageForm).GetEnumerator
        Return Me.m_FormCollection.GetEnumerator()
    End Function

    Public Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return Me.m_FormCollection.GetEnumerator()
    End Function

End Class
